<?php
class   ProductModel{
    var   $db;
    function   ProductModel(&$db)
    {
    $this-> db=$db;
    }
    function   listProducts(){
    return   $this-> db-> query($sql);
    }
    function   getProductInfo()
    {
    return   $this-db-> query($sql);
    }
}
class ProductView{
    var $model;
    var $template;
    var $smarty;
    function productView(&$model)
    {
        global $smarty;
        $this-> smarty = &$smarty;
        $this-> model = $model;
    }
    function listProducts()
    {
        $smarty-> assign( 'productlist ',$this-> model-> listProducts());
        $this-> setTemplate( 'listProduct.ptl ');
    }
    function getProductInfo()
    {
        $smarty-> assign( 'productinfo ',$this-> model-> getProductInfo());
        $this-> setTemplate( 'getProductInfo.ptl ');
    }
    funciton setTemplate($template)
    {
        $this-> template=$template;
    }
    function display()
    {
        $this-> smarty-> display($this-> template);
    }

}

class   ProductController   extends   ProductView{
    function   ProductControler($model,$_GET)
    {
        ProductView::ProductView($model);
        switch($_GET['action']){
            case 'listProduct'
                $this-> listProduct();
                break;
            case 'getProductInfo'
                $this-> getProductInfo();
        }
    }
}

//使用例子:
require_once( 'DB.php ');
require_once( 'Smarty.class.php ');
require_once( 'ProductModel.php ');
require_once( 'ProductView.php ');
require_once( 'ProudctController.php ');

$model = new ProductModel($db);
$controller = new ProductController($model,$_GET);
$controller->display();
?>